package com.career.syn;

import java.lang.reflect.Array;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author jasongu
 * @Description: TODO
 * @ClassName: ObjectUtil
 * @date 2018/12/27 15:05
 */
public class ObjectUtil {
    /**
     * 判断对象是否为空
     *
     * @param o
     * @return
     */
    public static boolean isEmpty(Object o) {
        if (o == null) {
            return true;
        }
        if (String.class.isAssignableFrom(o.getClass())) {
            String result = (String) o;
            return result.trim().length() == 0;
        } else if (List.class.isAssignableFrom(o.getClass())) {
            List<?> result = (List<?>) o;
            return result.size() == 0;
        } else if (Set.class.isAssignableFrom(o.getClass())) {
            Set<?> result = (Set<?>) o;
            return result.size() == 0;
        } else if (Map.class.isAssignableFrom(o.getClass())) {
            Map<?, ?> result = (Map<?, ?>) o;
            return result.size() == 0;
        } else if (o.getClass().isArray()) {
            return Array.getLength(o) == 0;
        }
        return false;
    }
}
